#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std;

const int MAXN=1e5+10;
long long t, n, a[MAXN], f[MAXN], m[MAXN*10];

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false);

    cin>>t;
    for(int ddd=0;ddd<t;ddd++){
        memset(a, 0, sizeof(a));
        memset(f, 0, sizeof(f));
        memset(m, 0, sizeof(m));
        cin>>n;
        for (int i=1;i<=n;i++){
            cin>>a[i];
        }
        for (int i=1;i<=n;i++){
            /*for (int j=1;j<i;j++){
                f[i]=max(f[i], f[j]);
            }*/
            for (int j=1;j<i;j++){
                if (a[i]==a[j]){
                    f[i]=max(f[i], f[i-1]+a[i]);
                }
                else f[i]=max(f[i], f[j]);
            }
        }
        cout<<f[n]<<endl;
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
